#region File Header
//----------------------------------------------------------------
// Copyright (C) 2002 Stefan Kyntchev
// All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR 
// FITNESS FOR A PARTICULAR PURPOSE.
//----------------------------------------------------------------
#endregion File Header

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Threading;
using AirWeb.Security;
using AirWeb.DirectoryMgr;
using AirWeb.ApplicationTools.Mail;
using AirWeb.Support.Diagnostics;

namespace FlashBack.Web
{
	/// <summary>
	/// Summary description for LoginPage.
	/// </summary>
	public partial class SendPassword : System.Web.UI.Page
	{
	
		public SendPassword()
		{
			Page.Init += new System.EventHandler(Page_Init);
		}

		protected void Page_Load(object sender, System.EventArgs e)
		{
			Response.Expires = -1;
		}

		protected void Page_Init(object sender, EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
		}

		public void SendMyPassword(object sender, CommandEventArgs e)
		{
			if(userEmail.Text == "")
			{
				InvalidEmail.Visible = true;
				return;
			}

			User u = SecurityMgr.Instance.GetUserByEmail(userEmail.Text);
			if(u == null)
			{
				InvalidEmail.Visible = true;
				return;
			}

			MailHelper m = new MailHelper("mailTemplateSendPasswd",this.Context);
			m.TemplateSubject = "Forgotten password request";
			m.AddRecipient(u);

			// Send the mail in a separate thread
			WaitCallback wcb = new WaitCallback(m.SendMail);
			ThreadPool.QueueUserWorkItem(wcb);
			
			ApplicationLog.WriteTrace("Forgotten password request for " + u.Name);

			//FormsAuthentication.SetAuthCookie(u.Name,false);
			Response.Redirect("Default.aspx");
		}

		#region Web Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion
	}
}
